public class SRMSystemTestPhase {

	public String[] record;
	public int[][][] dp;
	public static final int mod = 1000000007;

	public int countWays(String[] description) {
		record = description;
		dp = new int[description.length + 1][4][4];

		for (int i = 0; i <= description.length; i++)
			for (int j = 0; j < 4; j++)
				for (int k = 0; k < 4; k++)
					dp[i][j][k] = -1;

		return solve(0, 3, 0);
	}

	public int solve(int pos, int pass, int cha) {
		if (pos == record.length)
			return 1;
		if (dp[pos][pass][cha] > -1)
			return dp[pos][pass][cha];
		int ret = 0;
		int aa = record[pos].charAt(0) == 'Y' ? 3 : 1;
		int bb = record[pos].charAt(1) == 'Y' ? 3 : 1;
		int cc = record[pos].charAt(2) == 'Y' ? 3 : 1;

		// 0:pass;
		// 1:chad;
		// 2:failed;
		for (int mask = 0; mask < 8; mask++) {
			int passed = 0;
			int chad = 0;
			for (int i = 0; i < 3; i++) {
				if (record[pos].charAt(i) == 'Y')
					if ((1 & (mask >> i)) == 1) {
						passed++;
					} else
						chad++;
			}
			if (passed < pass || (passed == pass && chad >= cha))
				ret = (ret + solve(pos + 1, passed, chad)) % mod;
		}
		// for (int a = 0; a < aa; a++)
		// for (int b = 0; b < bb; b++)
		// for (int c = 0; c < cc; c++) {
		// int passed = 0;
		// int chad = 0;
		// if (record[pos].charAt(0) == 'Y' && a == 0)
		// passed++;
		// if (record[pos].charAt(0) == 'Y' && a == 1)
		// chad++;
		// if (record[pos].charAt(1) == 'Y' && b == 0)
		// passed++;
		// if (record[pos].charAt(1) == 'Y' && b == 1)
		// chad++;
		// if (record[pos].charAt(2) == 'Y' && c == 0)
		// passed++;
		// if (record[pos].charAt(2) == 'Y' && c == 1)
		// chad++;
		// if (passed < pass || (passed == pass && chad >= cha))
		// ret = (ret + solve(pos + 1, passed, chad)) % mod;
		// }
		return dp[pos][pass][cha] = ret;
	}
	 public static void main(String[] args)
	{
		long time;
		int answer;
		boolean errors = false;
		int desiredAnswer;
		
		
		time = System.currentTimeMillis();
		answer = new SRMSystemTestPhase().countWays(new String[]{"YYY"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 27;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new SRMSystemTestPhase().countWays(new String[]{"YNN", "NYN"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 6;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new SRMSystemTestPhase().countWays(new String[]{"YNN", "NNN", "NNY"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 4;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new SRMSystemTestPhase().countWays(new String[]{"NNN", "NNN"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 1;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		time = System.currentTimeMillis();
		answer = new SRMSystemTestPhase().countWays(new String[]{"YYY", "YNY", "NYY", "YYN", "YYY", "YNN"});
		System.out.println("Time: " + (System.currentTimeMillis()-time)/1000.0 + " seconds");
		desiredAnswer = 15176;
		System.out.println("Your answer:");
		System.out.println("\t" + answer);
		System.out.println("Desired answer:");
		System.out.println("\t" + desiredAnswer);
		if (answer != desiredAnswer)
		{
			errors = true;
			System.out.println("DOESN'T MATCH!!!!");
		}
		else
			System.out.println("Match :-)");
		System.out.println();
		
		
		if (errors)
			System.out.println("Some of the test cases had errors :-(");
		else
			System.out.println("You're a stud (at least on the test data)! :-D ");
	}

}
// Powered by [KawigiEdit] 2.0!
